﻿using GreenXi.ViewModel;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace GreenXi.Pages.Power
{
    /// <summary>
    /// Manual.xaml 的交互逻辑
    /// </summary>
    public partial class Manual : UserControl
    {
        public static ManualViewModel Instance { get; set; }
        public static ZedGraph.ZedGraphControl ZedGraphContro11;
        public static ZedGraph.ZedGraphControl ZedGraphControl2;

        public Manual()
        {
            InitializeComponent();
            Instance = new ManualViewModel(this);
            this.DataContext = Instance;
            ZedGraphContro11 = zedGraphControl1;
            ZedGraphControl2 = zedGraphControl2;


            // 订阅窗口的SizeChanged事件
            this.SizeChanged += Window_SizeChanged;

        }
        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            ZedHeight.Height = new GridLength(this.ActualWidth * 0.42, GridUnitType.Pixel);
        }
        private void OnMyVariableChanged(object sender, EventArgs e)
        {
            // 在这里刷新页面或更新相关的 UI 元素
            // 例如: MyTextBlock.Text = GlobalVariables.MyVariable.ToString();
        }

        public static void AxisChange(int num)
        {
            if (num == 1)
            {
                if (ZedGraphContro11 != null)
                {
                    //这里有bug，会导致系统卡死，复现方法为手动页面放着不动（可能要有曲线数据
                    ZedGraphContro11.AxisChange();
                    ZedGraphContro11.Invalidate();
                }
            }
            if (num == 2)
            {
                if (ZedGraphControl2 != null)
                {
                    ZedGraphControl2.AxisChange();
                    ZedGraphControl2.Invalidate();
                }
            }

        }
    

        private void lblTest_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (sender is IInputElement ele)
                            {
                                // 将鼠标捕获到触发该事件的元素
                Mouse.Capture(ele);
                          }
        }
         private void lblTest_MouseUp(object sender, MouseButtonEventArgs e)
        {
            Mouse.Capture(null);// 重置鼠标捕获
        }


private void lblTest_GotMouseCapture(object sender, MouseEventArgs e)
        {
            if (sender is IInputElement ele)
            {
                Mouse.Capture(ele);
            }
        }

        private void lblTest_LostMouseCapture(object sender, MouseEventArgs e)
        {
            Mouse.Capture(null);// 重置鼠标捕获
        }
    }
}
